package com.licq.ldoc.parser;

import java.lang.annotation.Annotation;

import com.licq.ldoc.config.Configuration;
import com.licq.ldoc.domain.Attribute;
import com.licq.ldoc.domain.Element;

/**
 * parse annotation to node
 * @author liujian
 *
 */
public abstract class AnnotationParsee {
	
	private AnnotationParsee successor;
	
	private Class<? extends Annotation> parseClazz;
	
	public static final AnnotationParsee NULL_PARSER = new AnnotationParsee(null) {
		@Override
		public void parse(Element element, Annotation annotation) {
		}
		
		@Override
		public void parse(Attribute attribute, Annotation annotation) {
		}
	};

	protected AnnotationParsee(AnnotationParsee successor) {
		this.successor = successor;
	}

	public void setParseClazz(Class<? extends Annotation> parseClazz) {
		this.parseClazz = parseClazz;
	}

	public void parse(Element element, Annotation annotation) {
		if (parseClazz == annotation.annotationType()) {
			doParse(element, annotation);
		} else {
			successor.parse(element, annotation);
		}
	}

	public void parse(Attribute attribute, Annotation annotation) {
		if (parseClazz == annotation.annotationType()) {
			doParse(attribute, annotation);
		} else {
			successor.parse(attribute, annotation);
		}
	}
	
	protected String getText() {
		return Configuration.getConfiguration().getString("text.annotation." 
				+ parseClazz.getSimpleName());
	}
	
	protected void doParse(Element element, Annotation annotation) {
	}

	protected void doParse(Attribute attribute, Annotation annotation) {
	}
	
}
